package com.cmpanyandi.elearning.utils.db.query;

public class LikeCondition extends QueryCondition {

    private LikeType likeType;
    /**
     * This constructor create like condition.
     * @param propertyName - name of property
     * @param value - value
     * @param likeType - enum type of like. 
     */
    public LikeCondition(String propertyName, String value, LikeType likeType) {
	this.likeType = likeType;
	setPropertyName(propertyName);
	setValue(value);
	
	
    }
    
    @Override
    public void setValue(String value) {
	String retValue = "";
	switch (likeType) {
	case LEFT:
	    retValue = "%" + value;
	    break;
	case RIGTH:
	    retValue = value + "%";
	    break;
	case ARROUD:
	    retValue = "%" + value + "%";
	    break;    
	default:
	    throw new RuntimeException("LikeType has to be defined.");
	}
	
	super.setValue(retValue);
    }
    
    @Override
    public String getConditionText() {
	return getPropertyName() + " like " + Q_MARK;
    }
    
    
    public enum LikeType {
	LEFT, RIGTH,ARROUD;
    }

}
